package team.fourth.combat.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team.fourth.combat.commen.constant.RedisConstant;
import team.fourth.combat.commen.entity.Result;
import team.fourth.combat.commen.utils.RedisUtil;
import team.fourth.combat.commen.utils.ValidateCodeUtils;

@RestController
@RequestMapping("/validateCode")
public class ValidateCodeController {

    @Autowired
    RedisUtil redisUtil;

     @RequestMapping("/send4Login")
     public Result send4Login(String telephone){
         //1、生成验证码
         Integer code = ValidateCodeUtils.generateValidateCode(4);

         //2、调用短信工具类发送短信
//        SmsUtil.sendSmsCode(telephone,String.valueOf(code));

         //3、把验证码存入redis（用户提交预约时需要校验）注意：redis key = 手机号码 + 后缀（能代码当前业务）
         redisUtil.setex(telephone+ RedisConstant.SENDTYPE_LOGIN_ADMIN,String.valueOf(code),60 * 5 * 100);

         return Result.success("短信发送成功");
     }
}
